Imports System.Xml.Serialization
Namespace Mapping

    Public Class Mapping
        Inherits XEntityModelElementBase

        ''' <summary>Initializes an instance of the <see cref="Mapping" /> class.
        ''' This is the default constructor for this class.</summary>
        Public Sub New()
            MyBase.New("Mapping", CSXmlNamespace)
        End Sub

        ''' <summary>Initializes an instance of the <see cref="Mapping" /> class.</summary>
        ''' <param name="other">An <see cref="System.Xml.Linq.XElement"/> object to copy from.</param>
        Public Sub New(ByVal other As XElement)
            MyBase.New(other)
        End Sub

        Private __alias As AliasCollection

        <AutoLoad()> _
        <XmlElement("Alias", GetType([Alias]))> _
        Public ReadOnly Property Aliases() As AliasCollection
            Get
                If (__alias Is Nothing) Then
                    __alias = New EdmxEditor.Mapping.AliasCollection(Me, MyBase.Name.Namespace, "Alias")
                End If
                Return __alias
            End Get
        End Property

        <AutoLoad()> _
        <XmlElement("EntityContainerMapping")> _
        Public Property EntityContainerMapping() As EntityContainerMapping
            Get
                Return DirectCast(Me.Element(MyBase.Name.Namespace + "EntityContainerMapping"), EdmxEditor.Mapping.EntityContainerMapping)
            End Get
            Set(ByVal value As EntityContainerMapping)
                If (DirectCast(value, XElement).Name <> (MyBase.Name.Namespace + "EntityContainerMapping")) Then
                    Throw New ArgumentException("Invalid Element")
                End If
                If (Me.EntityContainerMapping IsNot Nothing) Then
                    Me.EntityContainerMapping.Remove()
                End If
                Me.Add(New EdmxEditor.Mapping.EntityContainerMapping(value))
            End Set
        End Property

        <XmlAttribute()> _
        Public Property Space() As Space
            Get
                Return GetEnumValueAttribute(GetType(Space), Me.Attribute(XName.Get("Space", MyBase.Name.NamespaceName)))
            End Get
            Set(ByVal value As Space)
                If (Me.Attribute(XName.Get("Space", MyBase.Name.NamespaceName)) Is Nothing) Then
                    Me.Add(New XAttribute(XName.Get("Space", MyBase.Name.NamespaceName), ""))
                End If
                SetEnumValueAttribute(GetType(Space), Me.Attribute(XName.Get("Space", MyBase.Name.NamespaceName)), value)
            End Set
        End Property

    End Class

End Namespace
